<template>
  <div class="menu-container">
    <template v-for="v:object in menuList">
      <el-sub-menu :index="v.name" v-if="v.children && v.children.length > 0" :key="v.name">
        <template slot="title">
          <i class="iconfont" :class="v.meta.icon"></i>
          <span>{{ v.meta.name }}</span>
        </template>
        <el-menu-item-group>
          <DynamicMenu :menuList="v.children"></DynamicMenu>
        </el-menu-item-group>
      </el-sub-menu>
      <el-menu-item :key="v.name" :index="v.name" @click="gotoRoute(v.name)" v-else>
        <i class="iconfont" :class="v.meta.icon"></i>
        <span slot="title">{{ v.meta.name }}</span>
      </el-menu-item>
    </template>
  </div>
</template>

<script setup lang="ts">
import { defineProps } from 'vue'
import { useRouter } from 'vue-router'
const router = useRouter()

const props = defineProps({
  menuList: {
    type: Array,
    default: function () {
      return []
    }
  }
})

const gotoRoute = (name:string) => {
  router.push({name})
}
</script>

<style></style>